//
// Created by wenyaxi on 24-11-1.
//
#include <common.h>
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        vector<vector<int>> res;
        sort(intervals.begin(), intervals.end());
        for(auto & interval : intervals) {
            int start = interval[0];
            int end = interval[1];
            if(res.empty()||res.back()[1]<start) {
                res.push_back({start, end});
            }else {
                res.back()[1]=max(end, res.back()[1]);
            }
        }
        return res;
    }
};

int main(int argc, char *argv[]) {
    //[[1,3],[2,6],[8,10],[15,18]]
    Solution s;
    vector<vector<int>> intervals;
    intervals.push_back({1,3});
    intervals.push_back({2,6});
    intervals.push_back({8,10});
    intervals.push_back({15,18});
    auto vectors = s.merge(intervals);
    for(auto & v : vectors) {
        cout<<printer::int_array_to_string(v)<<endl;
    }
    return 0;
}
